<%@page import="java.io.PrintWriter"%>
<%@page import="java.util.List"%>
<%@page import="br.com.model.Pessoa"%>
<%@page import="br.com.controller.AgendaController"%>
<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Lista Pessoas</title>

</head>
<body>

<%-- <c:out value="${pessoa.nome}"/><br>
<c:out value="${pessoa}"/><br> --%>

<center>
<table border="1">
	<tr>
		<td>ID</td>
		<td>NOME</td>
		<td>SOBRENOME</td>
		<td>EMAIL</td>
		<td>TELEFONE</td>
		<td></td>
	</tr>	

<%

List<Pessoa> l = (List) request.getAttribute("lista"); 
for(Pessoa pessoa : l){
	out.println("<tr>");
	out.println("<td>"+pessoa.getId()+"</td>");
	out.println("<td>"+pessoa.getNome()+"</td>");
	out.println("<td>"+pessoa.getSobreNome()+"</td>");
	out.println("<td>"+pessoa.getEmail()+"</td>");
	out.println("<td>"+pessoa.getTelefone()+"</td>");
	out.println("<td>");
	out.println("<img src=\"/JavaWebHibernateHSQLDB/img/atualizar.png\" onclick=\"Controller(1,"+pessoa.getId()+")\"><img src=\"/JavaWebHibernateHSQLDB/img/cancelar.png\" onclick=\"Controller(0,"+pessoa.getId()+")\">");
	out.println("</td>");
	out.println("</tr>");	
}
%>

</table>
<br>
<input type="submit" value="Voltar" onclick="volta()">
</center>

<form action="AgendaController" method="post" id="formaced">
	<input type="hidden" id="editar" name="editar" value="editar">
	<input type="hidden" id="id" name="id" value="">
</form>

<form action="AgendaController" method="post" id="formacex">
	<input type="hidden" id="excluir" name="excluir" value="excluir">
	<input type="hidden" id="idexcluir" name="id" value="">
</form>

</body>

<script type="text/javascript">
function volta(){
	history.back(); 
}

function Controller(num,id){
	if(num == 1){
		$("#id").val(id);
		$("#formaced").submit();
		alert(id);
	}else{
		$("#idexcluir").val(id);
		$("#formacex").submit();
		alert(id);
	}
}

</script>

</html>